<?php

require_once "includes/Constant.php";
require_once "includes/cryptography/RC4Crypt.php";

/**
 * RC4 Handler Class
 * @package RC4CryptHandler
 */
class RC4CryptHandler {
	
	public static function encrypt ($data)
	{
		return self::bin2hex(RC4Crypt::encrypt(Constant::$RC4_KEY, $data, 0));
	}

	public static function decrypt ($data)
	{
		return RC4Crypt::encrypt(Constant::$RC4_KEY, self::hex2bin($data), 0);
	}

	private static function hex2bin($h)
	{
		if (!is_string($h)) return null;
		$r="";
		for ($a=0; $a<strlen($h); $a+=2) {
			$r.=chr(
				hexdec(
					$h{$a}.(isset($h{($a+1)})?$h{($a+1)}:"")
					)
				);
		}
		return $r;
	}
	
	private static function bin2hex($data)
	{
		return bin2hex($data);
	}
}
?>
